##    This file is part of The Most Awesome Story Ever
##
##    Foobar is free software: you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation, either version 3 of the License, or
##    (at your option) any later version.
##
##    Foobar is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
##    
##    Copyright 2008, Ryan Michela

from google.appengine.api import images

def prepareImage(imageData):
    """Resize a raw image and return the processed result and encoding type.
    
    This method processes the raw image data as both a jpeg and png image.
    The size of the two processed images is compared and the smaller one
    is returned as a touple of image type extension and image data.

    """
    
    jpeg = images.resize(imageData, 450, 300, images.JPEG)
    png = images.resize(imageData, 450, 300, images.PNG)
    
    if(len(jpeg) < len(png)):
        return ('jpg', jpeg)
    else:
        return ('png', png)
